package chixing.day07.inherited;

public class AnimalTest {
    public static void main(String[] args) {
//        Animal animal = new Animal("小猫",12f);
//        System.out.println(animal);
//
//        Dog dog1 = new Dog();
//        dog1.setAnimalName("小狗");
//        dog1.setAnimalWeight(24f);
//        dog1.setDogType("泰迪");
//        System.out.println(dog1);
//
//        Animal animal1 = new Dog();
//        animal1.setAnimalName("dog");
//        animal1.setAnimalWeight(34f);
//        System.out.println(animal1);

        //能否强制转换类型，看在内存中真正的类型
        Dog dog1 = new Dog();
        Animal animal1 = dog1;
        Dog dog2 = (Dog) animal1;//可以强制转换，因为animal1 在内存中的真正类型是dog类型

        //Dog dog = new Animal();    //报错，因为父类的类型不能用子类接收

        Animal animal3 = new Animal();
        Dog dog3 = (Dog) animal3;//强制转换失败，因为animal3 在内存中的真正类型是animal类型是dog的父类


    }
}
